const BaseHandler = require('../base-handler');
const SystemServices = require('../../../constants').SystemServices;
const HTTP_VERBS = require('../../../constants').HTTP_VERBS;
const moment = require('moment');

class ActionApiHandler extends BaseHandler {
    get pattern() {
        return "/admin/api/active";
    }

    doGET(request, response) {

        if (!request.session.user.authenticated) {
            response.json({
                success: false,
                error: '请登录系统后再调用此接口！'
            });
        } else {
            const params =  request.query;
            this.Controller.activeSearch(params, (result) => {
                if (result.error) {
                    return response.json({
                        success: false,
                        error: result.error
                    });
                }
                response.json({
                    success: true,
                    result: result
                });
            });

        }
    }

    doPOST(request, response) {
        var params = request.body;
        this.Controller.activeSearch(params, (result) => {
            if (result.error) {
                return response.json({
                    success: false,
                    error: result.error
                });
            }
            response.json({
                success: true,
                result: result
            });
        });
    }

    setup() {
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
        this.registerVerb(HTTP_VERBS.POST, this.doPOST);
    }
}

module.exports = ActionApiHandler;